var express = require('express');
var router = express.Router();
var query = require('./Database');
/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('ProAddress', {});
});
router.post('/address',async (req,res)=>{
    // console.log(req.body);
    let list = req.body;
    console.log('--------------');
    console.log(list);
    let rows = await query("select * from address where userid = " + list.userid + " and type = 1 or type = 2");
    // let goodsrows = await  query("select DISTINCT shopid,state,goodstime from goods");
    console.log('+++++++++++++++++++');
    console.log('+++++++++++++++++++');
    let data = [{code:100},rows];
    res.send(data);
});
router.post('/moren',async (req,res)=>{
    // console.log(req.body);
    let list = req.body;
    console.log('--------------');
    console.log(list);
    await query("update address set type = 1 where userid = " + list.userid + " and type = 2");
    await query("update address set type = 2 where userid = " + list.userid + " and id = " +list.id);
    // let goodsrows = await  query("select DISTINCT shopid,state,goodstime from goods");
    console.log('+++++++++++++++++++');
    console.log('+++++++++++++++++++');
    let data = {code:100};
    res.send(data);
});
router.post('/delete',async (req,res)=>{
    // console.log(req.body);
    let list = req.body;
    console.log('--------------');
    console.log(list);
    await query("update address set type = 0 where id = " +list.id);
    // let goodsrows = await  query("select DISTINCT shopid,state,goodstime from goods");
    console.log('+++++++++++++++++++');
    console.log('+++++++++++++++++++');
    let data = {code:100};
    res.send(data);
});
module.exports = router;